from django.db import models


class User(models.Model):  # 用户信息
    openid = models.CharField(max_length=30,primary_key=True)
    username = models.CharField(max_length=30)
    reg_time = models.DateTimeField()
    instruction = models.IntegerField(default=0)
    money = models.FloatField(default=10000)
    image_url = models.TextField()


class Fund(models.Model):  # 基金信息
    fund_id = models.CharField(max_length=20,primary_key=True,db_index=True)
    fund_name = models.CharField(max_length=40)
    category = models.IntegerField(default=0)  # 混合型 => 1   债券型 => 2    货币型 => 3     指数型 => 4
    buy_min = models.FloatField(default=0)
    manager = models.CharField(max_length=30)
    buy_source_rate = models.FloatField(default=0)
    buy_rate = models.FloatField(default=0)
    day_growth = models.FloatField(default=0)
    week_growth = models.FloatField(default=0)
    month_growth = models.FloatField(default=0)
    three_month_growth = models.FloatField(default=0)
    six_month_growth = models.FloatField(default=0)
    year_growth = models.FloatField(default=0)
    price = models.FloatField(default=0)


class Vary(models.Model):  # 基金变化表
    fund_id = models.CharField(max_length=30)
    net_asset_value = models.FloatField(default=0)
    value_rate = models.CharField(max_length=20)
    date = models.DateField()


class Position(models.Model):  # 持仓表
    fund_id = models.CharField(max_length=30)
    stock_id = models.CharField(max_length=30)
    stock_name = models.CharField(max_length=30)
    stock_rate = models.FloatField(default=0)


class Follow(models.Model):  # 用户关注基金表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)


class Popular(models.Model):  # 热门基金表
    fund_id = models.CharField(max_length=30)
    date = models.DateField()


class Rate(models.Model):   # 基金占比表
    fund_id = models.CharField(max_length=30)
    stock_rate = models.CharField(max_length=10)
    bond_rate = models.CharField(max_length=10)
    cash_rate = models.CharField(max_length=10)


class Size(models.Model):   # 基金规模表
    fund_id = models.CharField(max_length=30)
    size = models.CharField(max_length=10)
    date = models.DateField()


class Queue(models.Model):  # 交易队列表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)
    category = models.IntegerField(default=0)
    money = models.FloatField(default=0)
    number = models.FloatField(default=0)
    time = models.DateTimeField()


class Hold(models.Model):   # 用户持有表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)
    cost = models.FloatField(default=0)
    number = models.FloatField(default=0)


class Check(models.Model):  # 用户账单表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)
    number = models.FloatField(default=0)
    money = models.FloatField(default=0)
    time = models.DateTimeField()
    category = models.IntegerField(default=0)
    complete = models.IntegerField(default=0)
    buy_time = models.DateTimeField()


class Timing(models.Model): # 定投表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)
    money = models.FloatField(default=0)
    span = models.IntegerField(default=0)
    date = models.IntegerField(default=0)
    number = models.IntegerField(default=0)


class Remind(models.Model):     # 提醒表
    user_id = models.CharField(max_length=30)
    information = models.TextField()
    see = models.IntegerField(default=0)
    time = models.DateTimeField()
    type = models.IntegerField(default=0)  # 1 ==> 加仓  2 ==> 减仓  3 ==> 定投余额不足
    fund_id = models.CharField(max_length=30)
################  AI


class Click(models.Model):  # 点击次数表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)
    click_count = models.IntegerField(default=0)


class FundVector(models.Model):  # 基金特征向量表
    fund_id = models.CharField(max_length=30, primary_key=True)
    day1 = models.IntegerField(default=0)
    day2 = models.IntegerField(default=0)
    day3 = models.IntegerField(default=0)
    day4 = models.IntegerField(default=0)
    week1 = models.IntegerField(default=0)
    week2 = models.IntegerField(default=0)
    week3 = models.IntegerField(default=0)
    week4 = models.IntegerField(default=0)
    month1 = models.IntegerField(default=0)
    month2 = models.IntegerField(default=0)
    month3 = models.IntegerField(default=0)
    month4 = models.IntegerField(default=0)
    three_month1 = models.IntegerField(default=0)
    three_month2 = models.IntegerField(default=0)
    three_month3 = models.IntegerField(default=0)
    three_month4 = models.IntegerField(default=0)
    six_month1 = models.IntegerField(default=0)
    six_month2 = models.IntegerField(default=0)
    six_month3 = models.IntegerField(default=0)
    six_month4 = models.IntegerField(default=0)
    year1 = models.IntegerField(default=0)
    year2 = models.IntegerField(default=0)
    year3 = models.IntegerField(default=0)
    year4 = models.IntegerField(default=0)
    stock1 = models.IntegerField(default=0)
    stock2 = models.IntegerField(default=0)
    stock3 = models.IntegerField(default=0)
    stock4 = models.IntegerField(default=0)
    bond1 = models.IntegerField(default=0)
    bond2 = models.IntegerField(default=0)
    bond3 = models.IntegerField(default=0)
    bond4 = models.IntegerField(default=0)
    cash1 = models.IntegerField(default=0)
    cash2 = models.IntegerField(default=0)
    cash3 = models.IntegerField(default=0)
    cash4 = models.IntegerField(default=0)
    type1 = models.IntegerField(default=0)
    type2 = models.IntegerField(default=0)
    type3 = models.IntegerField(default=0)
    type4 = models.IntegerField(default=0)
    type5 = models.IntegerField(default=0)
    scale1 = models.IntegerField(default=0)
    scale2 = models.IntegerField(default=0)
    scale3 = models.IntegerField(default=0)
    scale4 = models.IntegerField(default=0)


class PreferenceVector(models.Model):  # 个人喜好向量表
    user_id = models.CharField(max_length=30, primary_key=True)
    day1 = models.FloatField(default=0)
    day2 = models.FloatField(default=0)
    day3 = models.FloatField(default=0)
    day4 = models.FloatField(default=0)
    week1 = models.FloatField(default=0)
    week2 = models.FloatField(default=0)
    week3 = models.FloatField(default=0)
    week4 = models.FloatField(default=0)
    month1 = models.FloatField(default=0)
    month2 = models.FloatField(default=0)
    month3 = models.FloatField(default=0)
    month4 = models.FloatField(default=0)
    three_month1 = models.FloatField(default=0)
    three_month2 = models.FloatField(default=0)
    three_month3 = models.FloatField(default=0)
    three_month4 = models.FloatField(default=0)
    six_month1 = models.FloatField(default=0)
    six_month2 = models.FloatField(default=0)
    six_month3 = models.FloatField(default=0)
    six_month4 = models.FloatField(default=0)
    year1 = models.FloatField(default=0)
    year2 = models.FloatField(default=0)
    year3 = models.FloatField(default=0)
    year4 = models.FloatField(default=0)
    stock1 = models.FloatField(default=0)
    stock2 = models.FloatField(default=0)
    stock3 = models.FloatField(default=0)
    stock4 = models.FloatField(default=0)
    bond1 = models.FloatField(default=0)
    bond2 = models.FloatField(default=0)
    bond3 = models.FloatField(default=0)
    bond4 = models.FloatField(default=0)
    cash1 = models.FloatField(default=0)
    cash2 = models.FloatField(default=0)
    cash3 = models.FloatField(default=0)
    cash4 = models.FloatField(default=0)
    type1 = models.FloatField(default=0)
    type2 = models.FloatField(default=0)
    type3 = models.FloatField(default=0)
    type4 = models.FloatField(default=0)
    type5 = models.FloatField(default=0)
    scale1 = models.FloatField(default=0)
    scale2 = models.FloatField(default=0)
    scale3 = models.FloatField(default=0)
    scale4 = models.FloatField(default=0)


class Preference(models.Model):  # 个人喜好表
    user_id = models.CharField(max_length=30, primary_key=True)
    scale1 = models.IntegerField(default=0)
    scale2 = models.IntegerField(default=0)
    scale3 = models.IntegerField(default=0)
    scale4 = models.IntegerField(default=0)
    term1 = models.IntegerField(default=0)
    term2 = models.IntegerField(default=0)
    term3 = models.IntegerField(default=0)
    term4 = models.IntegerField(default=0)
    stable = models.IntegerField(default=0)
    balance = models.IntegerField(default=0)
    advance = models.IntegerField(default=0)


class UserFundScore(models.Model):  # 个人基金评分表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)
    is_operated = models.IntegerField(default=0)
    score = models.FloatField(default=0)


class FundClick(models.Model):  # 每只基金每天点击次数表
    fund_id = models.CharField(max_length=30, primary_key=True)
    click_count = models.IntegerField(default=0)


##################### 评论相关功能
class Discussion(models.Model):     # 讨论表
    user_id = models.CharField(max_length=30)
    fund_id = models.CharField(max_length=30)
    text = models.TextField()
    time = models.DateTimeField()


class Reply(models.Model):     # 回复表
    user_id = models.CharField(max_length=30)
    discussion = models.ForeignKey(Discussion, on_delete=models.CASCADE)
    text = models.TextField()
    time = models.DateTimeField()


class DiscussionThumb(models.Model):    # 讨论点赞表
    user_id = models.CharField(max_length=30)
    discussion = models.ForeignKey(Discussion, on_delete=models.CASCADE)


class ReplyThumb(models.Model): # 评论点赞表
    user_id = models.CharField(max_length=30)
    reply = models.ForeignKey(Reply, on_delete=models.CASCADE)


##### 预测
class Predict(models.Model):
    fund_id = models.CharField(max_length=30, primary_key=True)
    category = models.IntegerField(default=0)
    growth = models.FloatField(default=0)


class High(models.Model):
    fund_id = models.CharField(max_length=20, primary_key=True, db_index=True)
    fund_name = models.CharField(max_length=40)
    category = models.IntegerField(default=0)  # 混合型 => 1   债券型 => 2    货币型 => 3     指数型 => 4
    day_growth = models.FloatField(default=0)
    price = models.FloatField(default=0)

